package com.asiainfo.crm.core.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.asiainfo.crm.system.model.User;
import com.asiainfo.crm.system.model.UserInfo;
import com.opensymphony.xwork2.ActionContext;

public class SessionInfo {
	public final static String USER_INFO = "USER_INFO";
	public final static String CURR_RESOURCE_ID = "CURR_RESOURCE_ID";
	public final static String CURR_RESOURCE_URL = "CURR_RESOURCE_URL";

	public static UserInfo getUserInfo() {
		return (UserInfo) ActionContext.getContext().getSession()
				.get(USER_INFO);
	}

	public static UserInfo getUserInfo(ActionContext actionContext) {
		return (UserInfo) actionContext.getSession().get(USER_INFO);
	}

	public static UserInfo getUserInfo(HttpServletRequest request) {
		return (UserInfo) request.getSession().getAttribute(USER_INFO);
	}
	
	public static UserInfo getUserInfo(HttpSession session){
		return (UserInfo)session.getAttribute(USER_INFO);
	}

	public static String getCurrResourceId(ActionContext actionContext) {
		return (String) actionContext.getSession().get(CURR_RESOURCE_ID);
	}

	public static String getCurrResourceId() {
		return (String) ActionContext.getContext().getSession().get(
				CURR_RESOURCE_ID);
	}

	public static String getCurrResourceUrl() {
		return (String) ActionContext.getContext().getSession().get(
				CURR_RESOURCE_URL);
	}
	
	public static User getUser(){
		return getUserInfo().getUser();
	}
	
	public static User getUser(ActionContext actionContext){
		return getUserInfo(actionContext).getUser();
	}
	
}
